import tensorflow as tf
import cv2
import os
import numpy as np

pb_file_path = 'model/output_graph.pb' 

def get_data(img_path): 
	img = cv2.imread(img_path)
	img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
	img = cv2.resize(img,(224,224))
	img = np.expand_dims(img,axis=0)
	img = (img/255.0-0.5)*2.0
	return img
 

with tf.Session() as sess:
	with tf.io.gfile.GFile(pb_file_path, 'rb') as f:
		graph_def=tf.compat.v1.GraphDef()
		graph_def.ParseFromString(f.read())
		sess.graph.as_default()
		_=tf.import_graph_def(graph_def, name='') # 导入计算图
	input = sess.graph.get_tensor_by_name('Placeholder:0')
	output = sess.graph.get_tensor_by_name('final_result:0')
	img = get_data('test1.jpg')
	out = sess.run(output,feed_dict={input:img})
	print(out)
	

